﻿using System;
using System.Collections.Generic;
using System.IO;

namespace CreateKeep
{
    /// <summary>
    /// 检测当前所在目录，将空目录中都创建一个.keep文件
    /// </summary>
    class Program
    {
        public static string packageFile = ".keep";  
        static void Main(string[] args)
        {
            var count = 0;
            string curDir = Directory.GetCurrentDirectory();
            Console.WriteLine($"当前目录：{curDir}");

            var dirs = Directory.GetDirectories(curDir,"*",SearchOption.AllDirectories);
            if (dirs.Length > 0)
            {
                //创建keep
                foreach (var dir in dirs)
                {
                    if (Directory.GetFileSystemEntries(dir).Length == 0)
                    {
                        var path = Path.Combine(dir, packageFile);
                        File.WriteAllText(path, "");
                        Console.WriteLine($"创建{path}");
                        count++;
                    }
                }
                Console.WriteLine($"共处理{count}个空文件夹。");
            }
            Console.WriteLine("按回车键退出");
            Console.ReadLine();
        }

    }
}
